package com.yhd.proxy.cglib;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author yhd
 * @email yinhuidong1@xiaomi.com
 * @description TODO
 * @since 2021/5/21 上午10:40
 */
public class ProxyFactory<T> {

    public static<T>  T getProxy(T t){
        return (T) Enhancer.create(t.getClass(), (MethodInterceptor) (o, method, objects, methodProxy) -> {
            System.out.println("增强");
            return method.invoke(t,objects);
        });
    }
}
